﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Passwords.Models;

namespace Passwords.Utils
{
    public class CategoryComparer : IComparer<CategoryContract>
    {
        private string name;
        private CategoryContract category;

        public CategoryContract Category
        {
            get { return category; }
            set
            {
                category = value;
                string n = category.Name;
                name = n != null ? n.ToLowerInvariant() : null;
                CompareName = name;
            }
        }

        public string CompareName { get; set; }

        public int Compare(CategoryContract x, CategoryContract y)
        {
            if (x == category)
            {
                return string.CompareOrdinal(CompareName.ToLowerInvariant(), name);
            }
            return string.CompareOrdinal(x.Name.ToLowerInvariant(), name);
        }
    }
}
